#ifndef CENTERWIDGET_H
#define CENTERWIDGET_H

#include <camera.h>
#include <QOpenGLWidget>
#include <QOpenGLFunctions>
#include <QOpenGLShaderProgram>
#include <QOpenGLTexture>
#include <QOpenGLVertexArrayObject>
#include <QOpenGLBuffer>
#include <QTime>
#include "element/element.h"

class CenterWidget : public QOpenGLWidget, protected QOpenGLFunctions
{
    Q_OBJECT
public:
    explicit CenterWidget(QWidget *parent = nullptr);
    ~CenterWidget();

    std::vector<Element*> eles;

    // 重置中心
    void setCenter(double x, double y, double z);
private:
    QTime time = QTime::currentTime();
    QOpenGLShaderProgram ourShader;
    int g=0;
    Camera* camera;
    QOpenGLTexture *texture1;

    QOpenGLBuffer VBO;
    QOpenGLBuffer EBO;
    QOpenGLVertexArrayObject VAO;
signals:
    void updateGL(QOpenGLShaderProgram &shader);

protected:

    virtual void initializeGL(); // 初始化，vao, vbo,着色器，纹理，相机
    virtual void paintGL(); // 画，渲染一次，循环要添加update() 函数
    virtual void resizeGL(int w, int h); // 视图、窗口大小变化


    void keyPressEvent(QKeyEvent *event);
    void keyReleaseEvent(QKeyEvent *event);
    void mousePressEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void wheelEvent(QWheelEvent *event);

public:
    void addElement();
};

#endif // CENTERWIDGET_H
